package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.zlzxm.shoesmarket.globle.Constant;
import com.zlzxm.shoesmarket.net.BaseCallBack;
import com.zlzxm.shoesmarket.net.repository.OtherRepository;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * CREATE BY zlzxm ON 2021/5/20
 */
public class VMNavigationHome extends BaseViewModel{

    private OtherRepository otherRepository = new OtherRepository();

    public MutableLiveData<List<String>> liveBanner = new MutableLiveData<>();


    public void requestBanner(){

        otherRepository.banner()
                .compose(RxAndroidHelp.turn())
                .subscribe(new BaseCallBack<String>() {
                    @Override
                    protected void succeed(String msg, String s) {

                        liveBanner.setValue(createBanner(s));
                    }

                    @Override
                    protected void failed(String msg) {

                    }

                    @Override
                    protected void notLogin() {

                    }
                },throwableCallback);


    }


    private List<String> createBanner(String source){

        if (source.contains(Constant.Split.pic_split)){

            String[] pics = source.split(Constant.Split.pic_split);

            return   Arrays.asList(pics);


        }else {

            List<String> list = new ArrayList<>();

            list.add(source);

            return list;
        }

    }


}
